<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://photos">

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="../comments/defaultList.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="albumBar.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/comments.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
			<script type="text/javascript" src="{$baseURI}/js/baseComments.js" />
			<script type="text/javascript" src="{$baseURI}/js/photosComments.js" />
			
			<xsl:comment>[if IE]&gt;&lt;link rel="stylesheet" href="<xsl:value-of select="$baseURI"/>/css/photos-ie.css" type="text/css" media="all" /&gt;&lt;![endif]</xsl:comment>
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">				
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
					
					<xsl:if test="@user-group != 'guest'">
						<div class="block">
							<div id="arrow">
								<form>
									<xsl:attribute name="action">
										<xsl:if test="response/@album-owner-id = $userId">
											<xsl:value-of select="concat ($baseURI, '/photos/upload/', response/@album-id)" />
										</xsl:if>
										<xsl:if test="response/@album-owner-id != $userId">
											<xsl:text>/photos/upload</xsl:text>
										</xsl:if>
									</xsl:attribute>
									<span>
										<input type="submit" value="&labelUploadButton;" />
									</span>
								</form>
							</div>
							<p style="padding-left:30px;"><small>&labelCanCreateAlbum1; <a href="{$baseURI}/photos/create_album">&labelCanCreateAlbum2;</a></small></p>
						</div>
					</xsl:if>
					
					<div class="block">
						<h4>&labelBlockOtherAlbums;</h4>
						<div>
							<xsl:apply-templates select="document(concat('xmodule://photos/getUserAlbums/', response/@album-owner-id, ';', response/@album-id))/data/response" mode="block-user-albums" />
						</div>
					</div>
					
					<div class="block">
						<h4>&labelBlockCloud;</h4>
						<div>
							<xsl:apply-templates select="document('xmodule://photos/getTagsCloud')/data/response/tags" mode="block-tags-cloud" />
						</div>
					</div>
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
		<xsl:apply-templates select="object" />
	</xsl:template>
	
	<xsl:template match="object[@type='photo']">
		<xsl:param name="id" select="@id" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="title" select="property[@name='title']/value" />
		<xsl:param name="rating" select="property[@name='rating']/value" />
		<xsl:param name="allowVote" select="@allow-vote" />
		<xsl:param name="albumId" select="property[@name='album_id']/value" />		
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="prevId" select="@previous-id" />
		<xsl:param name="nextId" select="@next-id" />
		<xsl:param name="smallPhotos" select="document(concat('xmodule://photos/getAlbumPhotos/', @id))/data/response/photos" />
		
		<xsl:apply-templates select="document(concat('xobject://photoalbum/', $albumId))/data/object" mode="album-bar" />
		
		<h1 class="photo">
			<div>
				<xsl:if test="$title = ''">
					<xsl:text>&labelWithoutName;</xsl:text>
				</xsl:if>
				<xsl:if test="$title != ''">
					<xsl:value-of select="$title" />
				</xsl:if>
			</div>
			
			<xsl:apply-templates select="document(concat('xmodule://system/getVoted/', $rating, ';', $allowVote, ';', @type-id, ';', @id))/data/response/vote" mode="photo-vote" />
			
			<xsl:if test="property[@name='owner_id']/value = $userId or $userGroup = 'admin' or $userGroup = 'moderator'">
				<div style="margin-left:20px;">
					<a href="{$baseURI}/photos/edit/{$albumId}?photo[]={@id}">
						<img src="{$baseURI}/images/settings-icon.png" alt="" />
					</a>
					<xsl:text> </xsl:text>
					<a onclick="if(!confirm('&labelDeletePhotoConfirm;'))return false;" href="{$baseURI}/photos/delete_photo/{@id}">
						<img src="{$baseURI}/images/delete-icon.png" alt="" />
					</a>
				</div>
			</xsl:if>
		</h1>
		<div id="view_photo">
			<div id="photo">
				<a href="{$baseURI}/photo/{$nextId}" title="&labelNexPhoto;">
					<img alt="{$title}">
						<xsl:attribute name="src">
							<xsl:value-of select="concat ($baseURI, property[@name='photo']/value)" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div id="photo_controls">
				<p>
					<xsl:text>&labelAdded; </xsl:text>
					<xsl:value-of select="property[@name='date']/value" />
					<xsl:text> by </xsl:text>
					<a class="user" href="{$baseURI}/user/{$userLogin}">
						<xsl:value-of select="property[@name='user_name']/value" />
					</a>
				</p>
				
				<xsl:if test="property[@name='description']/value != ''">
					<p class="description">
						<xsl:value-of select="property[@name='description']/value" />
					</p>
				</xsl:if>
				
				<xsl:if test="count (property[@name='tags']/value) &gt; 0">
					<p>
						<xsl:text>&labelTags;: </xsl:text>
						<xsl:for-each select="property[@name='tags']/value">
							<a>
								<xsl:attribute name="href">
									<xsl:value-of select="concat ($baseURI, '/photos/tag/', .)" />
								</xsl:attribute>
								<xsl:value-of select="." />
							</a>
							<xsl:if test="position() != $countTags">
								<xsl:text>, </xsl:text>
							</xsl:if>
						</xsl:for-each>
					</p>
				</xsl:if>
			</div>
		</div>
				
		<ul id="photos_browser">
			<li>
				<a href="{$baseURI}/photoalbum/{$albumId}">
					<img src="{$baseURI}/images/photos-icon-all.png" alt="" />
				</a>
			</li>
			
			<xsl:for-each select="$smallPhotos/photo">
				<li>
					<xsl:if test="$id = id">
						<xsl:attribute name="class">
							<xsl:text>active</xsl:text>
						</xsl:attribute>
					</xsl:if>
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="concat ($baseURI, '/photo/', id)" />
						</xsl:attribute>
						<img alt="">
							<xsl:attribute name="src">
								<xsl:value-of select="concat ($baseURI, '/thumb_40_40', photo)" />
							</xsl:attribute>
						</img>
					</a>
				</li>
			</xsl:for-each>
			
		</ul>
		<xsl:text>
</xsl:text>
				
		<a name="comments" />
		<h3 class="comments">&labelComments; (<xsl:value-of select="property[@name='count_comments']/value" />):</h3>
		<div id="comments_div">
			<xsl:apply-templates select="document(concat('xmodule://comments/getComments/photo;', @id))/data/response" mode="comments" />
		</div>
	</xsl:template>
	
	<!-- PHOTO VOTE -->
	<xsl:template match="vote" mode="photo-vote">
		<xsl:param name="id" select="object_id" />
		<xsl:param name="vote" select="mark" />
		<xsl:param name="allow" select="allow" />
		<xsl:param name="typeId" select="type_id" />
		<xsl:param name="rating" select="rating" />
		
		<div id="photo_rating">
			<div>
				<a id="photo_vote_plus_{$id}" href="javascript:void(0);" title="&labelLike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '1'">
								<img src="{$baseURI}/images/post-voted-plus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '1'">
								<img src="{$baseURI}/images/post-vote-plus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePhoto (', $id, ', 1);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-plus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
			<div class="photo_rating_number" id="photo_rating_{$id}">
				<xsl:if test="number ($rating) &gt; 0">
					<xsl:attribute name="class">photo_rating_number plus</xsl:attribute>
					<xsl:text>+</xsl:text>
				</xsl:if>
				<xsl:if test="number ($rating) &lt; 0">
					<xsl:attribute name="class">photo_rating_number minus</xsl:attribute>
				</xsl:if>
				<xsl:value-of select="$rating" />
			</div>
			<div>
				<a id="photo_vote_minus_{$id}" href="javascript:void(0);" title="&labelDislike;">
					<xsl:choose>
						<xsl:when test="$allow = '0' and $vote = ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVote;');</xsl:text>
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
						</xsl:when>
						<xsl:when test="$allow = '0' and $vote != ''">
							<xsl:attribute name="onclick">
								<xsl:text>new Error ('&labelCantVoteAgain;');</xsl:text>
							</xsl:attribute>
							<xsl:if test="$vote = '0'">
								<img src="{$baseURI}/images/post-voted-minus.png" alt="" />
							</xsl:if>
							<xsl:if test="$vote != '0'">
								<img src="{$baseURI}/images/post-vote-minus-cant.png" alt="" />
							</xsl:if>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="onclick">
								<xsl:value-of select="concat ('votePhoto (', $id, ', 0);')" />
							</xsl:attribute>
							<img src="{$baseURI}/images/post-vote-minus.png" alt="" />
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>